const { DataTypes } = require("sequelize");
const sequelize = require("../config/sequelize");
const User = require("./user");

const Post = sequelize.define(
  "Post",
  {
    content: {
      type: DataTypes.TEXT,
      allowNull: false,
      comment: "文章内容",
    },
    imgs: {
      type: DataTypes.TEXT,
      comment: "图片",
    },
    likeNum: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: "点赞人数",
    },
    commentNum: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: "评论人数",
    },
    place: {
      type: DataTypes.STRING,
      allowNull: false,
      comment: "发布的地点",
    },
  },
  {
    // 这是其他模型参数
    sequelize: sequelize,
    tableName: "post",
    paranoid: true,
    underscored: true,
  }
);
Post.belongsTo(User, {
  constraints: false,
  foreignKey: "userId",
  as: "user",
});
module.exports = Post;
